<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加管理员</title>
    <link rel="stylesheet" href="__COMMON__/css/simple.css">
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
    <script src="__COMMON__/jquery.min.js"></script>
</head>
<body>

<form class="layui-form" action="" style="padding: 10px">

    <div class="layui-form-item">
        <label class="layui-form-label">选择角色</label>
        <div class="layui-input-block">
            <select name="role_id" lay-verify="required">
                <option value=""></option>
                {if !empty($role)}
                {foreach name="role" item="vo"}
                <option value="{$vo['role_id']}">{$vo['role_name']}</option>
                {/foreach}
                {/if}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">登录名</label>
        <div class="layui-input-block">
            <input type="text" name="admin_name" required  lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">昵称</label>
        <div class="layui-input-block">
            <input type="text" name="admin_nickname" required  lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" name="admin_password" required  lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="启用" checked>
            <input type="radio" name="status" value="0" title="禁用">
        </div>
    </div>

    <div class="layui-form-item" style="margin-top: 40px">
        <div class="layui-input-block">
            <button type="button" class="am-btn am-btn-success am-btn-sm" lay-submit lay-filter="subForm">立即提交</button>
            <button type="reset" class="am-btn am-btn-default am-btn-sm" >重置</button>
        </div>
    </div>
</form>

<script src="__STATIC__/layui/layui.js"></script>
<script>

    layui.use(['form', 'layer'], function() {
        var form = layui.form;
        var layer = layui.layer;

        // 监听提交
        form.on('submit(subForm)', function(data) {

            $.post('{:url("admin/add")}', data.field, function (res) {
                if (res.code == 0) {
                    layer.msg(res.msg);

                    setTimeout(function () {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.initTable();
                    }, 800);
                } else {
                    layer.msg(res.msg);
                }
            }, 'json');
            return false;
        });
    });
</script>
</body>
</html>